package com.msmap.apphome;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.util.Log;
import android.widget.Toast;

/**
 * 耳机的状态
 * Created by Administrator on 2016/10/22.
 */

public class HeadSetReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (AudioManager.ACTION_HDMI_AUDIO_PLUG.equals(action)){
            //判断intent对象的是否有state参数
            if (intent.hasExtra("state")){
                //获取状态
                //插入耳机状态
                if (intent.getIntExtra("state",-1)==1){
                    Toast.makeText(context, "耳机出入插入状态", Toast.LENGTH_SHORT).show();
                    Log.i("aaa", "onReceive: --->插进来了！");
                }else {
                    Toast.makeText(context, "耳机处于拔出状态", Toast.LENGTH_SHORT).show();
                    Log.i("aaa", "onReceive: --->拔出去了！");
                }
            }

        }
    }
}
